//
//  RowTableViewController.m
//  11210
//
//  Created by student on 16/3/4.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "RowTableViewController.h"

@interface RowTableViewController ()

@property(nonatomic,strong)NSArray *list;

@end

@implementation RowTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.list=@[@"C3PO", @"Tik-Tok", @"Robby", @"Rosie", @"Uniblab",
           @"Bender", @"Marvin", @"Lt. Commander Data",
           @"Evil Brother Lore", @"Optimus Prime", @"Tobor", @"HAL",
           @"Orgasmatron",@"C3PO", @"Tik-Tok", @"Robby", @"Rosie", @"Uniblab",
           @"Bender", @"Marvin", @"Lt. Commander Data",
           @"Evil Brother Lore", @"Optimus Prime", @"Tobor", @"HAL",
           @"Orgasmatron"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

}


#pragma mark - Table view data source



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text=self.list[indexPath.row];
    if (cell.accessoryView==nil) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=CGRectMake(0, 0, 50, 40);
        [btn setBackgroundImage:[UIImage imageNamed:@"button_up"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"button_down"] forState:UIControlStateHighlighted];
        [btn setTitle:@"点我" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
        cell.accessoryView=btn;
    }
    UIButton *btn = cell.accessoryView;
    btn.tag = indexPath.row;
    return cell;
}

-(void)btnPressed:(UIButton *)btn
{
NSLog(@"选中了%@",self.list[btn.tag]);
}


@end
